package com.sinodata.bsm.center.bean;

import com.sinodata.bsm.center.cache.AttributeCache;
import com.sinodata.bsm.center.util.spring.SpringContextHolder;
import com.sinodata.bsm.common.vo.Attribute;

/**
 * 
 * <p>
 * Description: 
 * </p>
 *
 * @author liulibo
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2012-6-28 下午2:29:49          liulibo        1.0         To create
 * </p>
 *
 * @since 
 * @see
 */
public class AttributeBean {

    /**
     * 属性POJO缓存
     */
    private static AttributeCache attributeCache = SpringContextHolder.getBean(AttributeCache.class);

    private Attribute vo;

    private ResTypeBean resTypeBean;

    /**
     * @directed
     * @supplierCardinality 1
     * @clientCardinality 1
     */
    private DataTypeBean dataTypeBean;

    private AttributeBean() {

    }

    /**
     * @param attr ResAttributeValue 对象的包含VO Bean
     */
    private AttributeBean(Attribute attr) {
        this.vo = attr;
    }

    /**
     * 通过属性ID得到属性对象
     * @param id int 属性ID
     * @return Attribute 属性对象
     */
    public static AttributeBean get(Long id) {
        return new AttributeBean(attributeCache.get(id));
    }

    /**
     * 获得属性的数据类型
     * @return DataType 数据类型对象
     */
    public DataTypeBean dataType() {
        if (dataTypeBean == null) {
            dataTypeBean = DataTypeBean.get(vo.getDataTypeId());
        }
        return dataTypeBean;
    }

    /**
     * 获得属性对象的VO bean
     * @return ResAttributeValue VO bean
     */
    public Attribute attribute() {
        return this.vo;
    }

    /**
     * 设置属性对象的VO bean
     * @param v ResAttributeValue VO bean
     */
    public void setAttribute(Attribute vo) {
        this.vo = vo;
    }

    public ResTypeBean getResTypeBean() {
        return resTypeBean;
    }

    public void setResTypeBean(ResTypeBean resTypeBean) {
        this.resTypeBean = resTypeBean;
    }

}